package development.hdk.node;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Point;
import android.graphics.Rect;
import development.hdk.mindmapfornandroid.Attributes;
import development.hdk.mindmapfornandroid.CommonResources;

public class CircularNode extends Node
{
  private static int iconPadding = 5;
  private static int padding = 5;
  Rect[] bounds;
  Rect defaultBounds = new Rect();
  String[] lines;
  Rect minBounds = new Rect();
  Rect rect = new Rect();

  public CircularNode(Context paramContext, float paramFloat1, float paramFloat2, int paramInt, Node paramNode, Attributes paramAttributes, CommonResources paramCommonResources)
  {
    super(paramContext, paramFloat1, paramFloat2, paramInt, paramNode, paramAttributes, paramCommonResources);
  }

  public CircularNode(Context paramContext, int paramInt1, int paramInt2, int paramInt3, Node paramNode, CommonResources paramCommonResources, Attributes paramAttributes)
  {
    super(paramContext, paramInt1, paramInt2, paramInt3, paramNode, paramCommonResources, paramAttributes);
  }

  public CircularNode(Context paramContext, Node paramNode)
  {
    super(paramContext, paramNode);
  }

  public boolean doesIntersect(int paramInt1, int paramInt2)
  {
    double d1 = this.width / 2.0D;
    double d2 = paramInt1 - (d1 + this.x);
    double d3 = paramInt2 - (d1 + this.y);
    if (Math.sqrt(d2 * d2 + d3 * d3) <= d1);
    /*for (int i = 1; ; i = 0)
      return i;*/
    return true;
  }

  public Point getLineConnection(float paramFloat1, float paramFloat2)
  {
    float f1 = this.x + this.width / 2.0F;
    float f2 = this.y + this.height / 2.0F;
    Point localPoint = null;
    if ((f1 == paramFloat1) && (f2 == paramFloat2))
    {
      localPoint = new Point(Math.round(f1), Math.round(f2));
      return localPoint;
    }
    float f3 = this.width / 2.0F / (float)Math.sqrt(Math.pow(Math.abs(f2 - paramFloat2), 2.0D) + Math.pow(Math.abs(f1 - paramFloat1), 2.0D));
    int i = Math.round(f3 * Math.abs(f1 - paramFloat1));
    int j = Math.round(f3 * Math.abs(f2 - paramFloat2));
    int k = Math.round(f1);
    int m = Math.round(f2);
    int n=0;
   /* if (k > paramFloat1)
    {
      n = k - i;
      label162: if (m <= paramFloat2)
        break label203;
    }
    label203: for (int i1 = m - j; ; i1 = m + j)
    {
      localPoint = new Point(n, i1);
      break;
      n = k + i;
      break label162;
    }*/
    if(k > paramFloat1)
    {
    	n = k - i;
    	if(m > paramFloat2)
    	{
    		for (int i1 = m - j; ; i1 = m + j)
    	    {
    	      localPoint = new Point(n, i1);
    	      n = k + i;
    	      break;
    	    }
    	}
    }
    return localPoint;
  }

  public Rect getNodeBounds()
  {
    float f1 = this.commonResources.getZoom();
    this.lines = this.text.split("\n");
    if (this.lines.length == 0)
    {
      String[] arrayOfString = new String[1];
      arrayOfString[0] = "";
      this.lines = arrayOfString;
    }
    this.bounds = new Rect[this.lines.length];
    float f2 = 0.0F;
    int i = (int)(30.0F * f1);
    if (i == 0)
      i = 1;
    this.textPaint.setTextSize(i);
    int j = Math.round(5.0F * f1);
    if (j == 0)
      j = 1;
    int k = Math.round(f1 * padding);
    int m = Math.round(2.0F * f1);
    int n = 0;
    if (this.isFocused)
      n = j;
    this.textPaint.getTextBounds("K|p", 0, "K|p".length(), this.defaultBounds);
    int i1=0,i2=0,i3=0,i4=0;
    if (i1 >= this.bounds.length)
    {
      this.textPaint.getTextBounds("e", 0, "e".length(), this.minBounds);
      if (f2 < this.minBounds.height())
        f2 = this.minBounds.height();
      i2 = 0;
      i3 = Math.round(f2) + m * (-1 + this.bounds.length);
      i4 = Math.round(i3 / 2.0F);
    }
    for (int i5 = 0; ; i5++)
    {
      if (i5 >= this.bounds.length)
      {
        if ((this.attributes.getShowIcon()) && (this.icon != null))
        {
          int i10 = this.bounds[0].height();
          int i11 = k + (i10 + (Math.round(f1 * iconPadding) + Math.round(i3 / 2.0F)));
          int i12 = (int)Math.round(Math.sqrt(Math.pow(k + Math.round(i10 / 2.0F), 2.0D) + Math.pow(i11, 2.0D)));
          if (i12 > i2)
            i2 = i12;
        }
        int i9 = i2 * 2 + j * 2 + n * 2;
        this.width = i9;
        this.height = i9;
        this.rect.set(0, 0, i9, i9);
        //return this.rect;
        this.bounds[i1] = new Rect();
        if ((this.lines[i1] == "") || (this.lines[i1] == null))
          this.textPaint.getTextBounds(" ", 0, " ".length(), this.bounds[i1]);
        while (true)
        {
          if (Math.abs(this.defaultBounds.bottom) > Math.abs(this.bounds[i1].bottom))
            this.bounds[i1].bottom = this.defaultBounds.bottom;
          if (Math.abs(this.defaultBounds.top) > Math.abs(this.bounds[i1].top))
            this.bounds[i1].top = this.defaultBounds.top;
          f2 += this.bounds[i1].height();
          i1++;
          this.textPaint.getTextBounds(this.lines[i1], 0, this.lines[i1].length(), this.bounds[i1]);
          break;
          
        }
      }
      int i6 = Math.round(this.bounds[i5].width() / 2.0F);
      int i7 = (int)Math.round(Math.sqrt(Math.pow(i6 + k, 2.0D) + Math.pow(k + Math.abs(i4), 2.0D)));
      if (i7 > i2)
        i2 = i7;
      int i8 = (int)Math.round(Math.sqrt(Math.pow(i6 + k, 2.0D) + Math.pow(k + Math.abs(i4 - this.bounds[i5].height()), 2.0D)));
      if (i8 > i2)
        i2 = i8;
      i4 = i4 - this.bounds[i5].height() - m;
    }
  }

  protected void onDraw(Canvas paramCanvas)
  {
    super.onDraw(paramCanvas);
    float f1 = this.commonResources.getZoom();
    this.textPaint.setTextSize(30.0F * f1);
    this.backgroundPaint.setColor(this.attributes.getBackgroundColor());
    this.borderPaint.setColor(this.attributes.getBorderColor());
    this.textPaint.setTextAlign(Paint.Align.CENTER);
    this.lines = this.text.split("\n");
    if (this.lines.length == 0)
    {
      String[] arrayOfString = new String[1];
      arrayOfString[0] = "";
      this.lines = arrayOfString;
    }
    this.bounds = new Rect[this.lines.length];
    float f2 = 0.0F;
    int i = (int)(30.0F * f1);
    if (i == 0)
      i = 1;
    this.textPaint.setTextSize(i);
    int j = Math.round(5.0F * f1);
    if (j == 0)
      j = 1;
    int k = 0;
    if (this.isFocused)
      k = j;
    int m = Math.round(2.0F * f1);
    this.textPaint.getTextBounds("K|p", 0, "K|p".length(), this.defaultBounds);
    int n = 0;
    int i1 = 0;
    //label438: int i2;
    int i2 = 0;
    int i3 = 0;
    int i4 = 0;
    if (n >= this.bounds.length)
    {
      this.textPaint.getTextBounds("e", 0, "e".length(), this.minBounds);
      if (f2 < this.minBounds.height())
        f2 = this.minBounds.height();
      i1 = Math.round(this.width / 2.0F - j - k);
      if (this.isFocused)
        paramCanvas.drawCircle(k + (i1 + j), k + (i1 + j), k + (i1 + j), this.shadowPaint);
      paramCanvas.drawCircle(k + (i1 + j), k + (i1 + j), i1 + j, this.borderPaint);
      paramCanvas.drawCircle(k + (i1 + j), k + (i1 + j), i1, this.backgroundPaint);
      this.textPaint.setColor(-16777216);
      i2 = Math.round(f2) + m * (-1 + this.bounds.length);
      i3 = k + (i1 + j) - Math.round(i2 / 2);
      i4 = k + (i1 + j);
    }
    for (int i5 = 0; ; i5++)
    {
      if (i5 >= this.bounds.length)
      {
        if ((this.attributes.getShowIcon()) && (this.icon != null))
        {
          int i7 = this.bounds[0].height();
          int i8 = Math.round(f1 * iconPadding);
          int i9 = k + (i1 + j) - Math.round(i7 / 2.0F);
          int i10 = k + (i1 + j) - Math.round(i2 / 2.0F + i7) - i8;
          Bitmap localBitmap = this.icon;
          Rect localRect = new Rect(i9, i10, i9 + i7, i10 + i7);
          paramCanvas.drawBitmap(localBitmap, null, localRect, null);
        }
        this.bounds[n] = new Rect();
        if ((this.lines[n] == "") || (this.lines[n] == null))
          this.textPaint.getTextBounds(" ", 0, " ".length(), this.bounds[n]);
        while (true)
        {
          if (Math.abs(this.defaultBounds.top) > Math.abs(this.bounds[n].top))
            this.bounds[n].top = this.defaultBounds.top;
          if (this.defaultBounds.bottom > this.bounds[n].bottom)
            this.bounds[n].bottom = this.defaultBounds.bottom;
          f2 += this.bounds[n].height();
          n++;
          this.textPaint.getTextBounds(this.lines[n], 0, this.lines[n].length(), this.bounds[n]);
          break;
        }
      }
      int i6 = i3 + Math.abs(this.bounds[i5].top);
      this.lines[i5] = this.lines[i5].trim();
      paramCanvas.drawText(this.lines[i5], i4, i6, this.textPaint);
      i3 = m + (i6 + this.bounds[i5].bottom);
    }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    Rect localRect = getNodeBounds();
    setMeasuredDimension(localRect.right, localRect.bottom);
  }
}